package com.mdc.mansion.web.modules.pay.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.mdc.mansion.web.modules.system.utils.UserUtils;
import com.mdc.mansion.dataaccess.modules.system.entity.User;

import com.mdc.mansion.dataaccess.common.persistence.Page;
import com.mdc.mansion.dataaccess.modules.pay.entity.RestaurantOrderPayRefund;
import com.mdc.mansion.core.modules.pay.RestaurantOrderPayRefundService;
import com.mdc.mansion.web.common.web.BaseController;
/**
 * 菜品接收设置Controller
 * @author xizf
 * @version 2018-08-10
 */
@Controller
@RequestMapping(value = "${adminPath}/pay/restaurantOrderPayRefund")
public class RestaurantOrderPayRefundController extends BaseController {

	@Autowired
	private RestaurantOrderPayRefundService restaurantOrderPayRefundService;
	
	@ModelAttribute
	public RestaurantOrderPayRefund get(@RequestParam(required=false) String id) {
		if (StringUtils.isNotBlank(id)){
			return restaurantOrderPayRefundService.get(id);
		}else{
			return new RestaurantOrderPayRefund();
		}
	}
	
	@RequiresPermissions("pay:restaurantOrderPayRefund:view")
	@RequestMapping(value = {"list", ""})
	public ModelAndView list(RestaurantOrderPayRefund restaurantOrderPayRefund) {
		Map<String, Object> model=new HashMap<String, Object>();
		Page<RestaurantOrderPayRefund> page = restaurantOrderPayRefundService.findPage(restaurantOrderPayRefund);
        model.put("page", page);
		ModelAndView modelAndView=new ModelAndView("modules/pay/restaurantOrderPayRefundList", model);
		return modelAndView;
	}
	
	@RequiresPermissions("pay:restaurantOrderPayRefund:view")
	@RequestMapping(value = "form")
	public ModelAndView form(RestaurantOrderPayRefund restaurantOrderPayRefund) {
		Map<String, Object> model=new HashMap<String, Object>();
		model.put("restaurantOrderPayRefund", restaurantOrderPayRefund);
		return new ModelAndView("modules/pay/restaurantOrderPayRefundForm",model);
	}
	

	@RequiresPermissions("pay:restaurantOrderPayRefund:edit")
	@RequestMapping(value = "save")
	public ModelAndView save(RestaurantOrderPayRefund restaurantOrderPayRefund,RedirectAttributes redirectAttributes) {
		User u=UserUtils.getUser();
		restaurantOrderPayRefund.setUpdateBy(u);
		if (StringUtils.isNotBlank(restaurantOrderPayRefund.getId())){
			restaurantOrderPayRefundService.updateSelective(restaurantOrderPayRefund);
		}else{
			restaurantOrderPayRefund.setCreateBy(u);
			restaurantOrderPayRefundService.save(restaurantOrderPayRefund);
		}
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
	@RequiresPermissions("pay:restaurantOrderPayRefund:edit")
	@RequestMapping(value = "delete")
	public ModelAndView delete(RestaurantOrderPayRefund restaurantOrderPayRefund,RedirectAttributes redirectAttributes) {
		restaurantOrderPayRefundService.delete(restaurantOrderPayRefund);
		this.addMessage(redirectAttributes, "操作成功");
		return new ModelAndView("redirect:./list");
	}
	
}
